package com.blueocean_health.care.management.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.blueocean_health.care.management.domain.base.OrderChargeInfo;
import com.blueocean_health.care.management.domain.dto.OrderFlowDto;
import com.blueocean_health.care.management.domain.ordervo.ChareOrderVo;
import com.blueocean_health.care.management.util.MyMapper;

/**
 * 订单流水表 2017年8月23日17:28:31
 * 
 * @author wuyanli
 *
 */
@Repository
public interface OrderChargeInfoMapper extends MyMapper<OrderChargeInfo> {

	/**
	 * 重写分页count方法 2018年5月2日13:59:44
	 * 
	 * @param map
	 * @return
	 */
	long getOrderFlowTotal(Map<String, String> map);

	/**
	 * 根据筛选条件查询订单流水列表 2017年8月23日17:29:55
	 * 
	 * @param map
	 * @return
	 */
	List<OrderFlowDto> getOrderFlowList(Map<String, String> map);

	/**
	 * 对查询结果内的所有金额进行汇总 2017年11月10日10:07:08
	 * 
	 * @param map
	 * @return
	 */
	Map<String, Object> getAmountCount(Map<String, String> map);

	@Select("select * from order_charge_info where hospital_id=#{hospitalId} and is_active=1 and receipt_number=#{receiptNumber}  and order_id <> #{orderId} and fee_type <> 3 ")
	List<OrderChargeInfo> checkReceipt(ChareOrderVo chareo);

	@Select("select * from order_charge_info where hospital_id=#{hospitalId} and is_active=1 and receipt_number=#{receiptNumber}  and fee_type = 3 ")
	List<OrderChargeInfo> getRefundOrderbyReceiptNumber(@Param("hospitalId") String hospitalId,
			@Param("receiptNumber") String receiptNumber);

	@Select("select receipt_number from order_charge_info where order_id=#{orderId} and is_active=1")
	List<String> getReceiptNumByOrderId(String orderId);

	@Select("select * from order_charge_info where order_id=#{orderId} and is_active=1 GROUP BY  receipt_number")
	List<OrderChargeInfo> getReceiptByOrderId(String orderId);

	@Select("SELECT sum(amount) FROM order_charge_info where order_id=#{orderId} and (fee_type=1 or fee_type=2) and is_active=1")
	Double AlreadyAmount(String orderId);

	@Select("select * from order_charge_info where order_id=#{orderId} and is_active=1")
	List<OrderChargeInfo> getChargeListByOrderId(String orderId);

	@Update("UPDATE order_charge_info set is_active=0 where order_id =#{orderId}")
	Boolean updateChargeIsActive(@Param("orderId") String orderId);

	@Update("UPDATE order_charge_info set is_active=0 where order_id in (#{orderId})")
	Boolean updateAllChargeActive(@Param("orderId") String orderId);


	@Update("UPDATE order_charge_info set is_active=0 where service_id =#{serviceId}")
	int deleteChargeByServiceId(@Param("serviceId")String serviceId);

	@Update("UPDATE order_charge_info set refund_status=#{status} where order_id=#{orderId}")
	Boolean updateRefundStatus(@Param("orderId") String orderId,@Param("status") String status);

}